//
//  STBaseViewController.m
//  STShoppingMall
//
//  Created by apple on 2018/9/14.
//  Copyright © 2018年 apple. All rights reserved.
//

#import "ZB_BaseViewController.h"

@interface ZB_BaseViewController ()

@end

@implementation ZB_BaseViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    //设置默认需要导航条
    self.isShowCustomBar = YES;
    
    //默认是有分割线的
    self.isShowBottomLine = YES;
    
    [self setBaseNavigationBarBackgroundColor:[UIColor whiteColor]];
    [self setBaseNavigationBarSeperatLineShow:YES];
    [self setBaseNavigationBarTitle:self.title];
    [self setBaseNavigationBarColor:[UIColor whiteColor]];
    self.baseContentView.backgroundColor = [UIColor whiteColor];
    [self setBaseNavigationBarColor:ZBColorChangeRGB(0x303030, 1.0)];
    
    
    self.statusStyle = UIStatusBarStyleLightContent;
    
    [self setLeftButtonImage:[UIImage imageNamed:@"navigation_back"]];
    [self addLeftButtonSelector:@selector(leftReturnClick)];
    
}

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    //打开侧滑手势
    self.navigationController.interactivePopGestureRecognizer.enabled = YES;
    
    self.statusStyle = UIStatusBarStyleDefault;
}

- (void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];
    [self dimissKeyBoard];
    [HUD dismissMessage];
}

-(void)leftReturnClick{
    if (self.navigationController) {
        if ([self.navigationController.viewControllers firstObject] == self) {
            [self dismissViewControllerAnimated:YES completion:nil ];
        }else {
            [self.navigationController popViewControllerAnimated:YES];
        }
    }else {
        [self dismissViewControllerAnimated:YES completion:nil];
    }
}

- (void)addBackButton:(SEL)selector
{
    if(selector == nil)
    {
        [self addLeftButtonSelector:@selector(gotoBack)];
    }
    else
    {
        [self addLeftButtonSelector:selector];
    }
}


- (void)setBackButtonImage:(UIImage *)image lightImage:(UIImage *)lightImage
{
    [self setLeftButtonImage:image];
    [self setLeftButtonLightImage:lightImage];
}


- (void)gotoBack{
    
    [self.navigationController popViewControllerAnimated:YES];
}

- (void)setupFullContentView{
    WS(weakSelf);
    [self.baseContentView mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.center.equalTo(weakSelf.view);
        make.size.equalTo(weakSelf.view);
    }];
    [self.view bringSubviewToFront:self.naviBarContentView];
}

- (void)dimissKeyBoard
{
    [self.view endEditing:YES];
}


- (void)dealloc
{
    NSLog(@"%@销毁了",self);
}

@end


